// pages/goods/detail/comment.js
const app = getApp();
Page({
    data: { page: 1, totalPage: 2, list: [], loading: false },
    onLoad(options) {
        this.setData(options)
        this.loadData();
    },
    onReachBottom() {
        this.loadData();
    },
    loadData() {
        if (this.data.page > this.data.totalPage || this.data.loading) {
            return;
        }
        this.setData({ loading: true })
        app.http.get("goods/comment-list", {
            data: { goods_id: this.data.id, page: this.data.page },
        }).then(r => {
            const list = this.data.list
            list.push(...r.data.comment_list)
            this.setData({
                goods: r.data.goods,
                loading: false,
                page: this.data.page + 1,
                totalPage: r.data.total,
                list,
                num: r.data.num
            })
            wx.stopPullDownRefresh()
        }).catch(err => {
            app.wxToast.error(err.message)
        })
    },
    onPullDownRefresh() {
        this.setData({
            page: 1,
            totalPage: 2,
            list: []
        })
        this.loadData()
    }
})